var HooAlerts = new Class({
    options: {
	cls: 'hooalert',
	duration: 2000
    },
    
    queue: [],

    index: 0,

    initialize: function (options)   {
	this.queue = [];
	if ($defined(options)) this.options = $merge(this.options, options);
    },

    show: function (text, options) {
	var opts = $defined(options)?$merge(this.options, options):this.options;
	var mainE = new Element('div');
	toppos = window.getScrollTop() + 10;
	this.queue.each(function (el) {
	    toppos+= el.getSize().y + 3;
	});
	mainE.setStyles({
	    position: 'absolute',
	    'top': toppos + 'px',
	    'right': '3px',
	    'display': 'block',
	    'opacity': 0
	}).addClass(opts.cls).injectInside(document.body);
	new Element('div', {'class': 'hooalerttext'}).injectInside(mainE).set('html', text);

	this.queue[this.index] = mainE;

	mainE._effect = new Fx.Morph(mainE, {duration:400}).start({
	    'opacity': [0, 0.75]
	});
	this.hide.delay(opts.duration, this, [this.index]);
	this.index++;
    },

    hide: function (index) {
	if ($defined(this.queue[index])) {
	    var e = this.queue[index];
	    if ($defined(e._effect)) {
		e._effect.cancel();
	    }
	    e._effect = new Fx.Morph(e, {
	        duration: 2000,
	        transition: Fx.Transitions.Sine.Elastic,
	        onSuccess: function () {
		    e.empty();
		    e.destroy();
		}
	    });
	    e._effect.start({
		'opacity': 0
	    });
	    delete(this.queue[index]);
	}
    }
});

var HooAlert = new HooAlerts();
